﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace D6_Value_Assistance_Manager
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class MainWnd : Window
    {
        protected DfsWrapper m_dfsWrapper = new DfsWrapper();

        public MainWnd()
        {
            InitializeComponent();
            populateRepositoryList();
        }

        protected void populateRepositoryList()
        {
            foreach (String repositoryName in m_dfsWrapper.Repositories)
            {
                m_repositoryListBox.Items.Add(repositoryName);
            }
        }

        private void m_getValueAssistanceButton_Click(object sender, RoutedEventArgs e)
        {
            String customType = null;
            customType = m_customTypeTextBox.Text;

            if (String.IsNullOrEmpty(customType))
            {
                return;
            }

            String customAttribute = null;
            customAttribute = m_customAttrTextBox.Text;

            if (String.IsNullOrEmpty(customAttribute))
            {
                return;
            }

            int selectedIndex = m_repositoryListBox.SelectedIndex;

            if (selectedIndex < 0)
            {
                return;
            }

            String selectedRepository = m_repositoryListBox.Items[selectedIndex].ToString();

            m_dfsWrapper.setCurrentRepository(selectedRepository);

            String[] valueAssistanceValues = null;
            valueAssistanceValues = m_dfsWrapper.displayValueAssistance(customType, customAttribute);

            if (null != valueAssistanceValues && valueAssistanceValues.Count() > 0)
            {
                foreach (String valueStr in valueAssistanceValues)
                {
                    m_valueAssistanceTextBox.Text += valueStr + ",";
                }
            }



        }

        private void m_updateValueAssistanceButton_Click(object sender, RoutedEventArgs e)
        {
            String customType = null;
            customType = m_customTypeTextBox.Text;

            if (String.IsNullOrEmpty(customType))
            {
                return;
            }

            String customAttribute = null;
            customAttribute = m_customAttrTextBox.Text;

            if (String.IsNullOrEmpty(customAttribute))
            {
                return;
            }

            int selectedIndex = m_repositoryListBox.SelectedIndex;

            if (selectedIndex < 0)
            {
                return;
            }

            String listOfValues = m_valueAssistanceTextBox.Text;

            if (String.IsNullOrEmpty(listOfValues))
            {
                return;
            }

            String selectedRepository = m_repositoryListBox.Items[selectedIndex].ToString();

            m_dfsWrapper.setCurrentRepository(selectedRepository);

            m_dfsWrapper.updateValueAssistance(customType, customAttribute, listOfValues);

        }
    }
}
